!> author: 左志华
!> date: 2022-07-16
!>
module test_sph_eos

    use testdrive, only: new_unittest, unittest_type, error_type, check
    use sph_kinds, only: rk
    use sph_eos, only: p_water, c0, p_water_morris, p_water_monaghan, B, p_ideal_gas
    implicit none
    private

    public :: collect_EoS

contains

    subroutine collect_EoS(testsuite)
        type(unittest_type), allocatable, intent(out) :: testsuite(:)

        allocate (testsuite, source=[ &
                  new_unittest('FUNC: p_water', test_p_water), &
                  new_unittest('FUNC: p_water_morris', test_p_water_morris), &
                  new_unittest('FUNC: p_water_monaghan', test_p_water_monaghan), &
                  new_unittest('FUNC: p_ideal_gas', test_p_ideal_gas) &
                  ])

    end subroutine collect_EoS

    subroutine test_p_water(error)
        type(error_type), allocatable, intent(out) :: error
        real(rk) :: p, c
        c0 = 1.0_rk
        call p_water(1000.0_rk, p, c)
        call check(error, c, c0, more="tait: c /= c0")
        if (allocated(error)) return
        call check(error, p, 0.0_rk, more="tait: p /= 0.0_rk")
    end subroutine test_p_water

    subroutine test_p_water_morris(error)
        type(error_type), allocatable, intent(out) :: error
        real(rk) :: p, c
        c0 = 1.0_rk
        call p_water_morris(1000.0_rk, p, c)
        call check(error, c, c0, more="morris: c /= c0")
        if (allocated(error)) return
        call check(error, p, 1000.0_rk, more="morris: p /= 0.0_rk")
    end subroutine test_p_water_morris

    subroutine test_p_water_monaghan(error)
        type(error_type), allocatable, intent(out) :: error
        real(rk) :: p, c
        B = 142.8_rk
        call p_water_monaghan(1010.0_rk, p, c)
        call check(error, c, 1.0300949191898578_rk, more="mangahan: c /= 1.0300949191898578_rk")
        if (allocated(error)) return
        call check(error, p, 10.300928280881005_rk, more="mangahan: p /= 10.300928280881005_rk")
    end subroutine test_p_water_monaghan

    subroutine test_p_ideal_gas(error)
        type(error_type), allocatable, intent(out) :: error
        real(rk) :: p, c

        call p_ideal_gas(1000.0_rk, 1.0_rk, p, c)
        call check(error, p, 399.99999999999989_rk, more="ideal_gas: p /= 399.99999999999989_rk")
        if (allocated(error)) return
        call check(error, c, 0.74833147735478811_rk, more="ideal_gas: c /= 0.74833147735478811_rk")

    end subroutine test_p_ideal_gas

end module test_sph_eos
